package com.android.loveseason;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class DialogView {
	
	private Context mContext = null;
	public DialogView(Context context) {
		
		mContext = context;
	}
	public  View getQuestionDialog(String question,ArrayList<String> chooses,OnItemClickListener listener){
		LinearLayout mLayout = null;
		LayoutParams params = null;
		ListView listview = null;
		SimpleAdapter adapter = null;
		TextView textview = null; 
		View rootView = null;
		ArrayList<HashMap<String,Object>> listData = new ArrayList<HashMap<String,Object>>(); 
		int IconId[] = {R.drawable.list_index1,R.drawable.list_index2,R.drawable.list_index3};
		
		params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		mLayout = new LinearLayout(mContext);
		mLayout.setOrientation(LinearLayout.VERTICAL);
		
		//insert textview
		textview = new TextView(mContext);
		textview.setText(question);
		mLayout.addView(textview);
		//insert the list
	    listview = new ListView(mContext); 
		for(int i = 0;i<chooses.size();i++){
			HashMap<String,Object> map = new HashMap<String,Object>();
			map.put("icon",IconId[i]);
			map.put("text",chooses.get(i));
			listData.add(map);
		}
		adapter = new SimpleAdapter(mContext,listData,
									R.layout.qdialoglistitem,
									new String[]{"icon","text"},
									new int[]{R.id.ChooseIndexImg_id,R.id.ChooserText_id});
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(listener);
		mLayout.addView(listview);
		mLayout.setPadding(50,0,0,0);
		
		rootView = mLayout.getRootView();
		rootView.setBackgroundResource(R.drawable.sectiondiaglogbg);
		
		return rootView;
	}
	public View getNormalTextView(ArrayList<String> list,Button LeftButton,Button RightButton){
		AbsoluteLayout mLayout = null;
		TextView mTextView = null;
		StringBuffer buffer = new StringBuffer();
		View rootView = null;
		ImageView bgView = null;
		
		mLayout = new AbsoluteLayout(mContext);
		//insert background image
		bgView = new ImageView(mContext);
		bgView.setImageResource(R.drawable.sectiondiaglogbg);
		AbsoluteLayout.LayoutParams view_image = new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,0,25);   
		mLayout.addView(bgView,view_image);
		//insert text
		mTextView = new TextView(mContext);
		for(int i = 0;i<list.size();i++){
			buffer.append(list.get(i).toString());
			buffer.append("\n");
		}
		mTextView.setId(1);
		mTextView.setText(buffer);
		mTextView.setGravity(0);
		AbsoluteLayout.LayoutParams view_text = new AbsoluteLayout.LayoutParams(400,LayoutParams.WRAP_CONTENT,25,65);   
		mLayout.addView(mTextView,view_text);
		
		//insert button left
		if(null != LeftButton){
			LeftButton.setBackgroundResource(R.drawable.arrow_left);
			AbsoluteLayout.LayoutParams view_LeftBtn = new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,20,0);   
			mLayout.addView(LeftButton, view_LeftBtn);
		}
		
	
		
		//insert button right
		if(null != RightButton){
			RightButton.setBackgroundResource(R.drawable.arrow_right);
			AbsoluteLayout.LayoutParams view_RightBtn = new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,340,0);   
			mLayout.addView(RightButton, view_RightBtn);
		}
		
		
		rootView = mLayout.getRootView();
		return rootView;
	}
	public  void updateNormalTextView(View dialogView,ArrayList<String> list){
		TextView textview = (TextView)dialogView.findViewById(1);
		
		StringBuffer buffer = new StringBuffer();
		for(int i = 0;i<list.size();i++){
			buffer.append(list.get(i).toString());
			buffer.append("\n");
		}
		textview.setText(buffer);
	}
}
